<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Lunwen;

/**
 * LunwenSearch represents the model behind the search form about `app\models\Lunwen`.
 */
class LunwenSearch extends Lunwen
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'updatetime', 'isfinish', 'addmanid', 'addtime'], 'integer'],
            [['lwno', 'sort', 'gdunit', 'gdno', 'lwname', 'lwname_en', 'lwtype', 'kwname', 'hxkwtype', 'issnno', 'cnno', 'address', 'iswork', 'publishdate', 'lwfbqk', 'reelno', 'numbertype', 'startpage', 'endpage', 'pagenum', 'logtime', 'wlk', 'gxjsly', 'limittime', 'authornum', 'discipline', 'isproject', 'projectids', 'xgxk', 'zdxk', 'addman', 'author', 'jsqk', 'kwlevel', 'mark'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Lunwen::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            //分页
            'pagination' => [
                'pageSize' => 10,
            ],
            //排序
            'sort'=>[
                'defaultOrder'=>[
                    'id'=>SORT_ASC,
                ]
            ]
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'publishdate' => $this->publishdate,
            'updatetime' => $this->updatetime,
            'isfinish' => $this->isfinish,
            'addmanid' => $this->addmanid,
            'addtime' => $this->addtime,
        ]);

        $query->andFilterWhere(['like', 'lwno', $this->lwno])
            ->andFilterWhere(['like', 'sort', $this->sort])
            ->andFilterWhere(['like', 'gdunit', $this->gdunit])
            ->andFilterWhere(['like', 'gdno', $this->gdno])
            ->andFilterWhere(['like', 'lwname', $this->lwname])
            ->andFilterWhere(['like', 'lwname_en', $this->lwname_en])
            ->andFilterWhere(['like', 'lwtype', $this->lwtype])
            ->andFilterWhere(['like', 'kwname', $this->kwname])
            ->andFilterWhere(['like', 'hxkwtype', $this->hxkwtype])
            ->andFilterWhere(['like', 'issnno', $this->issnno])
            ->andFilterWhere(['like', 'cnno', $this->cnno])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'iswork', $this->iswork])
            ->andFilterWhere(['like', 'lwfbqk', $this->lwfbqk])
            ->andFilterWhere(['like', 'reelno', $this->reelno])
            ->andFilterWhere(['like', 'numbertype', $this->numbertype])
            ->andFilterWhere(['like', 'startpage', $this->startpage])
            ->andFilterWhere(['like', 'endpage', $this->endpage])
            ->andFilterWhere(['like', 'pagenum', $this->pagenum])
            ->andFilterWhere(['like', 'logtime', $this->logtime])
            ->andFilterWhere(['like', 'wlk', $this->wlk])
            ->andFilterWhere(['like', 'gxjsly', $this->gxjsly])
            ->andFilterWhere(['like', 'limittime', $this->limittime])
            ->andFilterWhere(['like', 'authornum', $this->authornum])
            ->andFilterWhere(['like', 'discipline', $this->discipline])
            ->andFilterWhere(['like', 'isproject', $this->isproject])
            ->andFilterWhere(['like', 'projectids', $this->projectids])
            ->andFilterWhere(['like', 'xgxk', $this->xgxk])
            ->andFilterWhere(['like', 'zdxk', $this->zdxk])
            ->andFilterWhere(['like', 'addman', $this->addman])
            ->andFilterWhere(['like', 'author', $this->author])
            ->andFilterWhere(['like', 'jsqk', $this->jsqk])
            ->andFilterWhere(['like', 'kwlevel', $this->kwlevel])
            ->andFilterWhere(['like', 'mark', $this->mark]);

        return $dataProvider;
    }
}
